/**
 * 看板数据刷新相关
 */
export default {
  data() {
    return {
      refreshIntervalID: null
    };
  },
  methods: {
    refreshInterval() {
      const HOUR = 60 * 60 * 1000;
      if (!this.refreshIntervalID) { // 首次进入需先获取当前时间，计算整点差值
        const now = new Date();
        const nowTime = now.getTime();
        now.setMinutes(5); // 整点05分刷新
        now.setSeconds(0);
        const nextHourTime = now.getTime() + HOUR;
        const nextTime = nextHourTime - nowTime;
        console.info('margin next refresh ms', nextTime);
        this.refreshIntervalID = setTimeout(() => {
          this.refreshData();
          this.refreshInterval();
        }, nextTime);
        return;
      }
      this.clearRefreshInterval();
      this.refreshIntervalID = setInterval(() => {
        this.refreshData();
      }, HOUR);
    },
    clearRefreshInterval() {
      if (this.refreshIntervalID) clearInterval(this.refreshIntervalID);
    },
    refreshData() {
      this.layoutList.forEach((item, index) => {
        const _that = this;
        const dataInfo = this.dataInfoObj[item.i];
        if (dataInfo && !dataInfo.isUpdateRegularly) return; // 不需要刷新则返回
        setTimeout(() => {
          _that.getChartTableDetail(item.i, index, true);
        }, 100);
      });
    }
  }
};
